package com.cat.mrli.rat.util;

import java.util.Arrays;

/**
 * Created by MrLi on 2017/6/23.
 */

public final class MatrixHelper {


    /**
     * @param m
     * @param yFovInDegrees
     * @param aspect        屏幕的宽高比
     * @param n             到近处平面的距离
     * @param f             到远处平面的距离
     *                      <p>
     *                      焦距的计算方法 1/tan(视野/2) 视野必须小于180
     *                      <p>
     *                      </p>
     */
    public static void perspectiveM(float[] m, float yFovInDegrees, float aspect, float n, float f) {
        final float angleInRadians = (float) (yFovInDegrees * Math.PI / 180);
        final float a = (float) (1.0 / Math.tan(angleInRadians / 2.0));
        Arrays.fill(m, 0.0f);
        m[0] = a / aspect;
        m[5] = a;
        m[10] = -(f + n) / (f - n);
        m[11] = -1;
        m[14] = -(2 * f * n) / (f - n);
    }
}
